var customerMessage = {
	validation : function(regularExpression, value) {
		return regularExpression.test(value);
	},
	saveMessage : function() {
		var email = $("#email").val();
		var phone = $("#phone").val();
		var clientName = $("#clientName").val();
		var content = $("#content").val();

		if (clientName == null || clientName == '') {
			alert('请输入客户名称');
			return;
		}
		if (phone == null || phone == '') {
			alert('请输入手机号或电话,方便联系');
			return;
		}
		if (!(customerMessage.validation(customerMessage.phoneRE, phone) || customerMessage
				.validation(customerMessage.telRe, phone))) {
			alert('手机号或电话号码格式错误');
			return;
		}
		if (email != null && email != '') {
			if (!customerMessage.validation(customerMessage.emaillRE, email)) {
				alert('邮箱格式错误');
				return;
			}
		}

		if (content == null || content == '') {
			alert('请输入留言内容');
			return;
		}

		$.ajax({
			url : "/customermessage/save",
			type : "post",
			data : $("#form1").serialize(),
			dataType : "json",
			success : function(data) {
				if (data.success == '0') {
					alert('留言成功');
				} else {
					alert(data.errorMessage);
				}
			},
			error : function() {
				alert("系统异常,稍后再试")
			}
		});

	},

	emaillRE : /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/,// 邮箱正则
	phoneRE : /^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\d{8}$/,// 手机号正则
	telRe : /^0\d{2,3}-?\d{7,8}$/
// 电话号码正则
};